package com.example.springboot.controller;

import com.example.springboot.dao.UserDao;
import com.example.springboot.dto.UserDTO;
import com.example.springboot.entity.User;
import com.example.springboot.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;
import java.util.logging.Logger;

@RestController
public class TestController {
    private static final Logger logger = Logger.getLogger(TestController.class.getName());

    @Autowired
    private UserService userService;
    /**
     * 前端请求格式：form-date中key:parameter\value:输入的值
     * @param parameter
     * @return
     */
    @PostMapping("/parameter")
    public String exampleEndpoint(@RequestParam String parameter) {
        // 处理接收到的参数
        return "Received parameter: " + parameter;
    }

    /**
     * 前端请求格式：raw——>JSON {"parameter": "Hello"}
     * @param parameterMap
     * @return
     */
    @PostMapping("/parameter2")
    public String exampleEndpoint2(@RequestBody Map<String,String> parameterMap) {
        // 处理接收到的参数
        String parameter = parameterMap.get("parameter");
        return "Received parameter: " + parameter;
    }
    @RequestMapping("/selectUserByIdMybatis")
    public User selectUserByIdMybatis(@RequestBody UserDTO userDTO) {
        return userService.selectUserByIdMybatis(userDTO.getId());
    }
    @PostMapping("/selectUserByIdMybatisPlus")
    public User selectUserByIdMybatisPlus(@RequestBody Map<String,String> parameterMap) {
        // 处理接收到的参数
        return userService.selectUserByIdMybatisPlus(Integer.valueOf(parameterMap.get("id")));
    }
}
